<script>
import { getWechatSignature } from "@/common/js/getData.js";

export default {
  onLaunch: function (e) {
    const _this = this;
    if (e.query.mainboardId) {
      _this.globalData.mainboardId = e.query.mainboardId;
      uni.setStorage({
        key: "mainboardId",
        data: _this.globalData.mainboardId,
      });
    } else {
      uni.getStorage({
        key: "mainboardId",
        success(res) {
          _this.globalData.mainboardId = res.data;
        },
      });
    }
    this.getSignature();
  },
  onShow: function () {
    console.log("App Show");
  },
  onHide: function () {
    console.log("App Hide");
  },
  globalData: {
    mainboardId: "2134234532",
    networkName: "",
    serviceTime: "",
    phone: "400-895-1906",
    filings: "湘ICP备2024063680号",
  },
  methods: {
    // 获取微信签名
    getSignature() {
      const data = {
        url: location.href,
      };
      getWechatSignature(data)
        .then((res) => {
          const { result } = res;
          jWeixin.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: result.appId, // 必填，公众号的唯一标识
            timestamp: result.timestamp, // 必填，生成签名的时间戳
            nonceStr: result.nonceStr, // 必填，生成签名的随机串
            signature: result.signature, // 必填，签名
            url: result.url, // 必填，生成签名的随机串
            jsapi_ticket: result.jsapi_ticket, // 必填，生成签名的随机串
            jsApiList: ["scanQRCode"], // 必填，需要使用的JS接口列表
          });
          this.$isResolve();
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
  },
};
</script>

<style lang="less">
/*每个页面公共css */
@import url("@/common/less/common.less");
@import url("@/common/less/base.less");
</style>
